home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / inst-octave.cmd < prev    next >
OS/2 REXX Batch file  |  1997-08-14  |  30KB  |  887 lines

  1. /*
  2. *******************************************************************************
  3. ** Install and Setup script for Octave/2 Version 0.5                         **
  4. ** (c) Klaus Gebhardt, 1996 - 1997                                           **
  5. *******************************************************************************
  6. */
  7.  
  8. /*
  9. *******************************************************************************
  10. ** This script will make all the necessary changes in the following files:   **
  11. **                                                                           **
  12. **   1. CONFIG.SYS                                                           **
  13. **   2. .emacs                                                               **
  14. **   3. .octaverc                                                            **
  15. **     (or the file pointed to by the environment variable OCTAVE_INITFILE)  **
  16. **   4. %INFOPATH%dir                                                        **
  17. *******************************************************************************
  18. ** It will also copy the info files to the directoy pointed to by the        **
  19. ** variable INFOPATH, and it replaces emx.dll, emxlibcs.dll and              **
  20. ** termcap.dat, if the files coming with Octave/2 are newer than those       **
  21. ** on your system.                                                           **
  22. *******************************************************************************
  23. ** This script also creates a folder with a program object for Octave/2      **
  24. ** on the WPS.                                                               **
  25. *******************************************************************************
  26. ** ALL ORIGINAL FILES, WHICH ARE MODIFIED OR REPLACED BY THIS SCRIPT         **
  27. ** ARE BACKUPED IN THE DIRECTORY YOU HAVE OCTAVE/2 INSTALLED IN.             **
  28. *******************************************************************************
  29. ** NO WARRANTY!                                                              **
  30. *******************************************************************************
  31. */
  32.  
  33. "@echo off"
  34. debug = ">NUL 2>NUL"
  35. debug_mode = 0;
  36.  
  37. version     = "2.09";
  38. script_arc  = "SCRIPTS.ZIP";
  39. dlfcn_arc   = "DLFCN.ZIP";
  40.  
  41. default_dir.0 = 2;
  42. default_dir.1 = "h:/apps/science/octave-";
  43. default_dir.2 = "i:/apps/octave-";
  44.  
  45. config_modified   = 0;
  46. config.0.nr =  9;
  47. config.1.nr =  8; config.1.name = "LIBPATH=";             config.1.zeile = "";
  48. config.2.nr =  9; config.2.name = "SET PATH=";            config.2.zeile = "";
  49. config.3.nr = 16; config.3.name = "SET OCTAVE_HOME=";     config.3.zeile = "";
  50. config.4.nr = 12; config.4.name = "SET TERMCAP=";         config.4.zeile = "";
  51. config.5.nr =  9; config.5.name = "SET TERM=";            config.5.zeile = "";
  52. config.6.nr =  9; config.6.name = "SET HOME=";            config.6.zeile = "";
  53. config.7.nr = 20; config.7.name = "SET OCTAVE_INITFILE="; config.7.zeile = "";
  54. config.8.nr = 13; config.8.name = "SET INFOPATH=";        config.8.zeile = "";
  55. config.9.nr = 12; config.9.name = "SET GNUPLOT=";         config.9.zeile = "";
  56.  
  57. emacs_modified = 0;
  58. octaverc_modified = 0;
  59. dir_modified = 0;
  60.  
  61.  
  62. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  63. call SysLoadFuncs
  64.  
  65. parse upper arg option cmdl
  66.  
  67. /*
  68. *******************************************************************************
  69. ** Debug-Mode                                                                **
  70. *******************************************************************************
  71. */
  72. if (option == "/DEBUG") then
  73.   do
  74.     say "info: Running in DEBUG mode!";
  75.     "@echo on"
  76.     debug = ""
  77.     debug_mode = 1;
  78.   end
  79. else
  80.   do
  81.     debug_mode = 0;
  82.     cmdl = option;
  83.   end
  84.  
  85. /*
  86. *******************************************************************************
  87. ** Removing unnecessary files                                                **
  88. *******************************************************************************
  89. */
  90. if (cmdl == "/CLEAN") then
  91.   do
  92.     say "info: Removing all for running Octave/2" version "unnecessary files";
  93.     "del Change*.* *.zip COPY*.* BUGS NEWS NEWS.1 PROJECTS README.*" debug
  94.     "del ROADMAP SENDING.PAT THANKS" debug
  95.     "del updt-oct*.cmd *.old *.new emx* unzip.exe" debug
  96.     exit;
  97.   end
  98.  
  99. /*
  100. *******************************************************************************
  101. ** Wrong argument and usage message                                          **
  102. *******************************************************************************
  103. */
  104. if ((cmdl <> "/INSTALL") & (cmdl <> "/USAGE") & (cmdl <> "")) then
  105.   do
  106.     say "error: Unknown command line option!";
  107.     say "";
  108.     cmdl = "";
  109.   end
  110.  
  111. if ((cmdl == "/USAGE") | (cmdl == "")) then
  112.   do
  113.     say "Usage:"
  114.     say "  Type 'inst-octave /install' to install Octave/2" version;
  115.     say "  Type 'inst-octave /usage'   to see this message.";
  116.     say "  Type 'inst-octave /clean'   to remove unnecessary files.";
  117.     say "on FAT systems you must type 'inst-oct' instead of 'inst-octave'";
  118.     exit;
  119.   end
  120.  
  121. /*
  122. *******************************************************************************
  123. ** Installation or Uodating the installation                                 **
  124. *******************************************************************************
  125. */
  126. say "info: Installing Octave/2" version "..."
  127.  
  128. boot_drive = get_boot_drive();
  129. say "info: OS/2 booted from" boot_drive;
  130.  
  131. octave_home = to_unix_sep(directory());
  132. octave_dll = octave_home || "/dll";
  133. if (check_octave_files(octave_home, 1) == 0) then
  134.   do
  135.     say "error: Run this script from within in the directory octave is"
  136.     say "error: installed in! If you are installing from the sources, you"
  137.     say "error: must compile Octave" version "before running this script!"
  138.     say "error: To do so, type: make -f makefile.os2"
  139.     exit;
  140.   end
  141. say "info: Octave/2 is installed in" octave_home || ".";
  142.  
  143. /* Analyse the CONFIG.SYS */
  144. octave_old_home = read_config_sys(boot_drive, octave_home);
  145. if (octave_old_home == "") then
  146.   do
  147.     say "info: There is no OCTAVE_HOME in your config.sys and also no";
  148.     say "info: entry in LIBPATH and SET PATH corresponding to an";
  149.     say "info: Octave/2 directory: This is the first installation of";
  150.     say "info: Octave/2 on this system.";
  151.     octave_old_dll = "";
  152.   end
  153. else
  154.   do
  155.     say "info: I found an old version of Octave/2 in your config.sys.";
  156.     say "info: This version was installed in:" octave_old_home;
  157.     say "info: I will remove all entries pointing to that version!"
  158.     octave_old_dll = octave_old_home || "/dll";
  159.   end
  160.  
  161. /* Replace older DLLs coming with EMX, if necessary */
  162. call emx_dlls config.1.zeile, "emx.dll"
  163. call emx_dlls config.1.zeile, "emxlibcs.dll"
  164.  
  165. /* Modify LIBPATH, PATH and OCTAVE_HOME */
  166. if to_upper(octave_old_home) <> to_upper(octave_home) then
  167.   do
  168.     config_modified = 1;
  169.     config.1.zeile = subst_paths(config.1.zeile, octave_old_dll,  octave_dll);
  170.     config.2.zeile = subst_paths(config.2.zeile, octave_old_home, octave_home);
  171.   end
  172.  
  173. if (to_upper(octave_home) <> to_upper(default_dir.1 || version)) then
  174.   do
  175.     if (to_upper(config.3.zeile) <> to_upper(octave_home)) then
  176.       do
  177.         config_modified = 1;
  178.         config.3.zeile  = octave_home;
  179.       end
  180.   end
  181. else
  182.   do
  183.     if (to_upper(config.3.zeile) <> "") then
  184.       do
  185.         config_modified = 1;
  186.         config.3.zeile  = "";
  187.       end
  188.   end
  189.  
  190. /* Modify TERMCAP, TERM and move TERMCAP.DAT */
  191. if (config.4.zeile <> "") then
  192.   do
  193.     if ((octave_old_home == "") | (to_upper(octave_old_home || "/etc/termcap.dat") <> to_upper(config.4.zeile))) then
  194.       do
  195.         config.4.zeile = emx_termcap(config.4.zeile);
  196.       end
  197.     else config.4.zeile = "";
  198.   end
  199.  
  200. if (config.4.zeile == "") then
  201.   do
  202.     config.4.zeile  = octave_home || "/etc/termcap.dat";
  203.     config_modified = 1;
  204.   end
  205.  
  206. if (config.5.zeile == "") then
  207.   do
  208.     config.5.zeile  = "ansi";
  209.     config_modified = 1;
  210.   end
  211.  
  212. /* Set the thie home directory to the root of your boot drive. */
  213. if (config.6.zeile == "") then
  214.   do
  215.     config.6.zeile  = boot_drive || "/.";
  216.     config_modified = 1;
  217.   end
  218.  
  219. /* Create or modify .octaverc */
  220. octave_rc = update_octaverc(config.6.zeile, config.7.zeile, octave_old_home, octave_home);
  221. if (to_upper(octave_rc) <> to_upper(config.7.zeile)) then
  222.   do
  223.     config.7.zeile = octave_rc;
  224.     config_modified = 1;
  225.   end
  226.  
  227. /* Modify INFO_PATH */
  228. if (config.8.zeile == "") then
  229.   do
  230.     config.8.zeile  = ".;" || octave_home || "/doc";
  231.     config_modified = 1;
  232.   end
  233. else
  234.   do
  235.     if (pos(";", config.8.zeile) == 0) then
  236.       do
  237.         len_info_path = length(config.8.zeile);
  238.         if (substr(config.8.zeile, len_info_path, 1) == "/") then
  239.           do
  240.             old_info_path = substr(config.8.zeile, 1, len_info_path-1);
  241.           end
  242.         else
  243.           do
  244.             old_info_path = config.8.zeile;
  245.           end
  246.         config.8.zeile = ".;" || old_info_path;
  247.         config_modified = 1;
  248.       end
  249.     info_path = to_unix_sep(subst_paths(config.8.zeile, octave_old_home || "/doc", octave_home || "/doc"));
  250.     call info_path_dir info_path, octave_home, version
  251.   if (to_upper(info_path) <> to_upper(config.8.zeile)) then
  252.     do
  253.       config.8.zeile = info_path;
  254.       config_modified = 1;
  255.     end
  256.   end
  257.  
  258. /* Modify or Add the variable GNUPLOT */
  259. if (config.9.zeile == "") then
  260.   do
  261.     fullgplt = SysSearchPath(PATH, "gnuplot.exe");
  262.     if (fullgplt <> "") then
  263.       do
  264.         pathgplt = filespec("drive", fullgplt) || filespec("path", fullgplt);
  265.         gplt = to_unix_sep(substr(pathgplt, 1, length(pathgplt)-1));
  266.         if (gplt <> config.9.zeile) then
  267.           do
  268.             config.9.zeile = gplt;
  269.             config_modified = 1;
  270.           end
  271.       end
  272.   end
  273.  
  274. /* Unzip the files for dynamic loading */
  275. call unzip_dlfcn_files dlfcn_arc
  276.  
  277. /* Unzip the script files */
  278. call unzip_script_files script_arc
  279.  
  280. /* Install on the WPS */
  281. if (debug_mode == 0) then call create_wps_object octave_home, version
  282.  
  283. rc = ini_files(config.6.zeile, ".emacs", "emacs", octave_old_home, octave_home);
  284. if (rc == 2) then
  285.   do
  286.     if (debug_mode == 0) then
  287.       do
  288.         "copy emacs.new" to_os2_sep(config.6.zeile) || "\.emacs" debug
  289.       end
  290.     say "info: EMACS MUST BE RESTARTED!"
  291.   end
  292.  
  293. if (config_modified == 1) then
  294.   do
  295.     call write_config_new boot_drive, octave_home
  296.     if (debug_mode == 0) then
  297.       do
  298.         "copy config.new" boot_drive || "\config.sys" debug
  299.       end
  300.     say "info: YOU MUST REBOOT YOUR SYSTEM!";
  301.   end
  302.  
  303. say "info: Done.";
  304. exit;
  305.  
  306. /*
  307. *******************************************************************************
  308. ** Write the modified config.sys                                             **
  309. *******************************************************************************
  310. */
  311. write_config_new: procedure expose config. debug version
  312. parse arg boot, dir
  313.   config_old = to_os2_sep(dir) || "\config.old";
  314.   config_new = to_os2_sep(dir) || "\config.new";
  315.   "del" config_new debug
  316.  
  317.   rc = stream(config_old, "C", "open read");
  318.   if rc <> "READY:" then
  319.     do
  320.       say "error: Cannot open the backup of CONFIG.SYS!";
  321.       exit;
  322.     end
  323.  
  324.   rc = stream(config_new, "C", "open write");
  325.   if rc <> "READY:" then
  326.     do
  327.       say "error: Cannot open CONFIG.NEW!";
  328.       rc = stream(config_old, "C", "close");
  329.       exit;
  330.     end
  331.  
  332.   say "info: Writing" config_new "...";
  333.   do while(lines(config_old))
  334.     line = linein(config_old);
  335.     do i=1 to config.0.nr
  336.       if (to_upper(substr(strip(line), 1, config.i.nr)) == config.i.name) then
  337.         do
  338.           if config.i.zeile <> "" then
  339.             do
  340.               p = pos(to_upper(config.i.name), to_upper(config.i.name));
  341.               if (p <= 1) then
  342.                 line = config.i.name || config.i.zeile;
  343.               else
  344.                 line = substr(" ",1,p," ") || config.i.name || config.i.zeile;
  345.               config.i.zeile = "";
  346.             end
  347.           leave;
  348.         end
  349.     end
  350.     call lineout config_new, line
  351.   end
  352.  
  353.   sep = 0;
  354.   do i=1 to config.0.nr
  355.     if (config.i.zeile <> "") then
  356.       do
  357.         if (sep == 0) then
  358.           do
  359.             call lineout config_new, ""
  360.             call lineout config_new, "REM Octave/2" version
  361.             sep = 1;
  362.           end
  363.         call lineout config_new, config.i.name || config.i.zeile;
  364.         config.i.zeile = "";
  365.       end
  366.   end
  367.  
  368.   rc = stream(config_new, "C", "close");
  369.   rc = stream(config_old, "C", "close");
  370.   return;
  371.  
  372. /*
  373. *******************************************************************************
  374. ** Analysing CONFIG.SYS:                                                     **
  375. *******************************************************************************
  376. */
  377. read_config_sys: procedure expose config. default_dir. debug
  378. parse arg boot, dir
  379.   config_old = to_os2_sep(dir) || "\config.old";
  380.   say "info: Copying" boot || "\config.sys to" config_old "...";
  381.   "copy" boot || "\config.sys" config_old debug
  382.  
  383.   rc = stream(config_old, "C", "open read");
  384.   if (rc <> "READY:") then
  385.     do
  386.       say "error: Cannot open the backup of CONFIG.SYS!";
  387.       exit;
  388.     end
  389.  
  390.   say "info: Analysing" config_old "...";
  391.   do while(lines(config_old))
  392.     line  = strip(linein(config_old));
  393.     do i=1 to config.0.nr
  394.       strupper = to_upper(substr(line, 1, config.i.nr));
  395.       if (strupper == config.i.name) then
  396.         do
  397.           config.i.zeile = substr(line, config.i.nr+1);
  398.           leave;
  399.         end
  400.     end
  401.   end
  402.   rc = stream(config_old, "C", "close");
  403.  
  404.   if (config.1.zeile == "") then
  405.     do
  406.       say "error: No "LIBPATH" statement found!";
  407.       exit;
  408.     end
  409.   else libpath = config.1.zeile;
  410.  
  411.   if (config.2.zeile == "") then
  412.     do
  413.       say "error: No "SET PATH" statement found!";
  414.       exit;
  415.     end
  416.   else path = config.2.zeile;
  417.  
  418.   oh = config.3.zeile;
  419.   if (oh <> "") then return to_unix_sep(oh);
  420.   else
  421.     do
  422.       do i = 1 to default_dir.0
  423.         oh = check_octave_old_home(default_dir.i, libpath, path);
  424.         if (oh <> "") then return to_unix_sep(oh);
  425.       end
  426.     end
  427.   return "";
  428.  
  429. check_octave_old_home: procedure expose debug
  430. parse arg str, libpath, path
  431.   string = to_os2_sep(str);
  432.   pa = 0;
  433.   do while(1)
  434.     pa = pos(to_upper(string), to_upper(path), pa + 1);
  435.     if (pa == 0) then return "";
  436.     if (pa <> 1) then
  437.       do
  438.         if (substr(path, pa - 1, 1) <> ";") then iterate;
  439.       end
  440.     pe = pos(";", path, pa);
  441.     if (pe == 0) then old_home = substr(path, pa);
  442.     else              old_home = substr(path, pa, pe-pa);
  443.     qa = pos(to_upper(old_home || "\DLL"), to_upper(libpath));
  444.     if (qa == 0) then iterate;
  445.     if (qa <> 1) then
  446.       do
  447.         if (substr(path, qa - 1, 1) <> ";") then iterate;
  448.       end
  449.     qe = pos(";", libpath, qa);
  450.     if qe == 0 then old_dll = to_upper(substr(libpath, qa));
  451.     else            old_dll = to_upper(substr(libpath, qa, qe-qa));
  452.     if (to_upper(old_home || "\DLL") == old_dll) then
  453.       do
  454.     flag = check_octave_files(old_home, 0);
  455.     if (flag == 0) then
  456.           do
  457.             say "notice: I FOUND AN OLD OCTAVE DIRECTORY ("fullpath") IN";
  458.             say "notice: LIBPATH AND PATH, BUT WITHOUT ANY OCTAVE FILES.";
  459.             say "notice: SHOULD I REMOVE ALL ENTRIES IN LIBPATH AND PATH";
  460.             say "notice: POINTING TO THAT DIRECTORY [Y/N]";
  461.             parse pull in;
  462.             flag = (in == "Y") | (in == "y");
  463.           end
  464.         if (flag) then return to_unix_sep(old_home);
  465.       end
  466.     else  return "";
  467.   end
  468.  
  469. check_octave_files: procedure expose debug
  470. parse arg string, flag
  471.   path = to_os2_sep(string);
  472.   rc = SysFileTree(path || "\octave.exe",     exe, "FO");
  473.   rc = SysFileTree(path || "\octave.ico",     ico, "FO");
  474.   rc = SysFileTree(path || "\dll\cruft?.dll", crt, "FO");
  475.   if (flag <> 0) then rc = SysFileTree(path || "\dll\octave?.dll", oct, "FO");
  476.   else                oct.0 = 2;
  477.   res = (exe.0 == 1) & (ico.0 == 1) & (crt.0 == 4) & (oct.0 == 2);
  478.   return res;
  479.  
  480. /*
  481. *******************************************************************************
  482. ** Updating the emx TERMCAP.DAT                                              **
  483. *******************************************************************************
  484. */
  485. emx_termcap: procedure expose debug
  486. parse arg termcap
  487.   call SysFileTree "etc\termcap.dat", oct_datei, "FT";
  488.   if oct_datei.0 <> 1 then return termcap;
  489.   if datei.1 > 80 then oct = "19" || oct_datei.1;
  490.   else                 oct = "20" || oct_datei.1;
  491.  
  492.   call SysFileTree to_os2_sep(termcap), emx_datei, "FT";
  493.   if emx_datei.0 <> 1 then return "";
  494.   if datei.1 > 80 then emx = "19" || emx_datei.1;
  495.   else                 emx = "20" || emx_datei.1;
  496.  
  497.   if oct == emx then return termcap;
  498.   if oct > emx then
  499.     do
  500.       say "info: Replacing" to_os2_sep(termcap) "...";
  501.       "copy" to_os2_sep(termcap) "termcap.old" debug
  502.       "copy etc\termcap.dat" to_os2_sep(termcap) debug
  503.     end
  504.   else
  505.     do
  506.       say "info: Removing termcap.dat coming with Octave/2 ...";
  507.       "del etc\termcap.dat" debug
  508.       "rd etc" debug
  509.     end
  510.  
  511.   return termcap;
  512.  
  513. /*
  514. *******************************************************************************
  515. ** Replacing the emx-DLLs                                                    **
  516. *******************************************************************************
  517. */
  518. emx_dlls: procedure expose debug
  519. parse arg libpath, file
  520.   call SysFileTree "dll\" || file, oct_datei, "FT";
  521.   if oct_datei.0 <> 1 then return;
  522.   if datei.1 > 80 then oct = "19" || oct_datei.1;
  523.   else                 oct = "20" || oct_datei.1;
  524.  
  525.   count = 0;
  526.   do while(1)
  527.     n = setlocal();
  528.     "SET OCTAVE_LIBPATH=" || libpath
  529.     fullpath = SysSearchPath(OCTAVE_LIBPATH, file);
  530.     if fullpath == "" then leave;
  531.     call SysFileTree fullpath, emx_datei, "FT";
  532.     if emx_datei.0 <> 1 then leave;
  533.     if datei.1 > 80 then emx = "19" || emx_datei.1;
  534.     else                 emx = "20" || emx_datei.1;
  535.     n = endlocal();
  536.  
  537.     if oct == emx then leave;
  538.     if oct > emx then
  539.       do
  540.         count = count+1;
  541.         bak_file = substr(file, 1, length(file)-3) || count;
  542.         "copy" fullpath bak_file debug
  543.         say "info: Older DLL (" || file || ") saved as:" bak_file;
  544.         say "info: Removing DLL (" || file || ") ...";
  545.         rc = 1;
  546.         do while(rc <> 0)
  547.           rc = SysFileDelete(fullpath);
  548.           if rc <> 0 then
  549.             do
  550.               say "notice: UNABLE TO DELETE FILE:" fullpath;
  551.               say "notice: THE DLL IS USED BY ONE OR MORE EMX PROGRAMS!";
  552.               say "notice: KILL ALL THOSE PROGRAMS BEFORE CONTINUING!";
  553.               say "notice: PRESS ENTER, WHEN READY ...";
  554.               parse pull in;
  555.             end
  556.         end            
  557.       end
  558.     else
  559.       do
  560.         say "info: Removing" file "coming with Octave/2 ...";
  561.         "del dll\" || file debug;
  562.         leave;
  563.       end
  564.   end
  565.   return;
  566.  
  567. /*
  568. *******************************************************************************
  569. ** Updating .octaverc                                                        **
  570. *******************************************************************************
  571. */
  572. update_octaverc: procedure expose debug debug_mode version
  573. parse arg home, initfile, old, new
  574.   if (initfile == "") then octrc = ".octaverc";
  575.   else                     octrc = initfile;
  576.  
  577.   octrc_new = "octaverc.new";
  578.   rc = ini_files(home, octrc, "octaverc", old, new);
  579.   if (rc == -1) then
  580.     do
  581.       "del" octrc_new debug
  582.       rc = stream(octrc_new, "C", "open write");
  583.       if (rc == "READY:") then
  584.         do
  585.           call lineout octrc_new, "# Startup file"
  586.           call lineout octrc_new, "# Octave" version "for OS/2"
  587.           call lineout octrc_new, "# (c) 1996 - 1997, Klaus Gebhardt"
  588.           rc = stream(octrc_new, "C", "close");
  589.           rc = 2;
  590.         end
  591.       else
  592.         do
  593.           say "error: Cannot create octaverc.new!";
  594.          exit;
  595.         end
  596.     end
  597.  
  598.   if (rc == 2) then
  599.     do
  600.       "del" to_os2_sep(home) || "\" || octrc debug
  601.       octrc_ini = to_os2_sep(home) || "\octave.ini"
  602.       "copy" octrc_new octrc_ini debug
  603.       "ren" octrc_ini ".octaverc" debug
  604.       rc = stream(octrc_ini, "C", "open read");
  605.       if (rc == "READY:") then
  606.         do
  607.           rc = stream(octrc_new, "C", "close");
  608.           rc = stream(octrc_ini, "C", "open write");
  609.           call lineout octrc_new, ''
  610.           call lineout octrc_new, 'history_file = "octave.hst"'
  611.           rc = stream(octrc_new, "C", "close");
  612.           return "octave.ini";
  613.         end
  614.       return "";
  615.     end
  616.   return initfile;
  617.  
  618. /*
  619. *******************************************************************************
  620. ** Modify the files .emacs, .octaverc                                        **
  621. *******************************************************************************
  622. */
  623. ini_files: procedure expose debug
  624. parse arg home, inifile, newfile, oldpath, newpath
  625.   file = to_os2_sep(home) || "\" || inifile;
  626.   ini_old = newfile || ".old";
  627.   ini_new = newfile || ".new";
  628.   say "info: Copying" file "to" ini_old "...";
  629.   "copy" file ini_old debug
  630.  
  631.   old = to_unix_sep(oldpath);
  632.   new = to_unix_sep(newpath);
  633.  
  634.   rc = stream(ini_old, "C", "open read");
  635.   if (rc <> "READY:") then return -1;
  636.  
  637.   "del" ini_new debug;
  638.   rc = stream(ini_new, "C", "open write");
  639.   if (rc <> "READY:") then
  640.     do
  641.       say "info: Cannot open" ini_new || "!";
  642.       rc = stream(ini_old, "C", "close");
  643.       exit;
  644.     end
  645.  
  646.   if (to_upper(old) == to_upper(new)) then return 0;
  647.  
  648.   rv = 1;
  649.   do while(lines(ini_old))
  650.     line  = linein(ini_old);
  651.     p = pos(to_upper(old), to_upper(line));
  652.     if (p <> 0) then
  653.       do
  654.         rv = 2;
  655.         if (p == 1) then
  656.           do
  657.             line = new || substr(line, 1+length(old));
  658.           end
  659.         else
  660.           do
  661.             line = substr(line, 1, p-1) || new || substr(line, p+length(old));
  662.           end
  663.       end
  664.     call lineout ini_new, line
  665.   end
  666.  
  667.   rc = stream(ini_new, "C", "close");
  668.   rc = stream(ini_old, "C", "close");
  669.   return rv;
  670.  
  671. /*
  672. *******************************************************************************
  673. ** Remove old INFO files, modify all dir files                               **
  674. *******************************************************************************
  675. */
  676. info_path_dir: procedure expose debug
  677. parse arg info_path, octave_home, version
  678.   infopath = to_os2_sep(info_path);
  679.   octaveinfopath = to_os2_sep(octave_home || "/doc");
  680.  
  681.   p = 1;
  682.   q = 1;
  683.   do while (q > 0)
  684.     q = pos(";", infopath, p);
  685.     if (q == 0) then infodir = substr(infopath, p);
  686.     else             infodir = substr(infopath, p, q - p);
  687.     p = q + 1;
  688.  
  689.     if (infodir == ".")  then iterate;
  690.     if (to_upper(infodir) == to_upper(octaveinfopath)) then iterate;
  691.  
  692.     say "info: Removing old info files in" infodir;
  693.     "del" infodir || "\octave" debug
  694.     "del" infodir || "\octave.i0?" debug
  695.     "del" infodir || "\octave.i1?" debug
  696.     "del" infodir || "\liboct" debug
  697.     "del" infodir || "\liboct.i0?" debug
  698.     "del" infodir || "\faq" debug
  699.     "del" infodir || "\oct-faq" debug
  700.  
  701.     file = infodir || "\dir"
  702.     dir_old = "dir" || p || ".old";
  703.     dir_new = "dir" || p || ".new";
  704.     say "info: Copying" file "to" dir_old "...";
  705.     "copy" file dir_old debug
  706.  
  707.     rc = stream(dir_old, "C", "open read");
  708.     if (rc <> "READY:") then return;
  709.  
  710.     "del" dir_new debug;
  711.     rc = stream(dir_new, "C", "open write");
  712.     if (rc <> "READY:") then
  713.       do
  714.         say "error: Cannot open" dir_new || "!";
  715.         rc = stream(dir_old, "C", "close");
  716.         exit;
  717.       end
  718.  
  719.     line = " ";
  720.     do while(lines(dir_old))
  721.       if line == d2c(31) then call lineout dir_new, line
  722.       line  = linein(dir_old);
  723.       parse var line w1 w2 ":" w3 "." w4
  724.       if ((w1 <> "*") | ((to_upper(w3) <> "(FAQ)") & (to_upper(w3) <> "(OCT-FAQ)") & (to_upper(w3) <> "(OCTAVE)") & (to_upper(w3) <> "(LIBOCT)"))) then
  725.         do
  726.           if line <> d2c(31) then call lineout dir_new, line
  727.         end
  728.     end
  729.  
  730.     call lineout dir_new, "* octave:    (octave).      Octave" version || "."
  731.     call lineout dir_new, "* liboctave: (liboct).      Info about liboctave" version || "."
  732.     call lineout dir_new, "* octave-faq:(oct-faq).     FAQs about Octave" version || "."
  733.    call lineout dir_new, d2c(31)
  734.  
  735.     rc = stream(dir_new, "C", "close");
  736.     rc = stream(dir_old, "C", "close");
  737.  
  738.     say "info: Copying" dir_new "to" file "...";
  739.     "copy" dir_new file debug
  740.   end
  741.   return;
  742.  
  743. /*
  744. *******************************************************************************
  745. ** Unzip DLFCN files                                                         **
  746. *******************************************************************************
  747. */
  748. unzip_dlfcn_files: procedure expose debug
  749. parse arg dlfcn
  750.   ".\unzip -o" dlfcn debug
  751.   return;
  752.  
  753. /*
  754. *******************************************************************************
  755. ** Unzip script files                                                        **
  756. *******************************************************************************
  757. */
  758. unzip_script_files: procedure expose debug
  759. parse arg zipfile
  760.   rc = SysFileTree(zipfile, fs, "F");
  761.   if fs.0 = 0 then return;
  762.   rc = SysFileTree("ChangeLog", fs, "F");
  763.   if fs.0 = 1 then scr = "scripts/*";
  764.   else             scr = "scripts.fat/*";
  765.   say "info: Unzipping scriptfiles ...";
  766.   if fs.0 = 0 then "ren scripts scripts.fat";
  767.   ".\unzip -o" zipfile scr debug
  768.   if fs.0 = 0 then "ren scripts.fat scripts";
  769.   return;
  770.  
  771. /*
  772. *******************************************************************************
  773. ** Create a WPS object for Octave/2                                          **
  774. *******************************************************************************
  775. */
  776. create_wps_object: procedure expose debug
  777. parse arg octave_home, version
  778.  
  779.   octave_folder_id = "<HWB_OCTAVE_FOLDER>";
  780.  
  781.   call SysCreateObject "WPFolder", "Octave/2", "<WP_DESKTOP>", ,
  782.        "OBJECTID="||octave_folder_id, "fail"
  783.  
  784.   object_name = "Octave" version;
  785.   octave_file = to_os2_sep(octave_home) || "\octave.exe";
  786.   octave_icon = to_os2_sep(octave_home) || "\octave.ico";
  787.  
  788.   rc = SysCreateObject("WPProgram", object_name, octave_folder_id, ,
  789.        "EXENAME="octave_file";PROGTYPE=WINDOWABLEVIO;ICONFILE="octave_icon||,
  790.        ";OBJECTID=<HWB_OCTAVE>", "replace");
  791.  
  792.   if rc == 1 then say "info: Program object for Octave created successfully."
  793.   else            say "notice: Could not create program object for Octave."
  794.  
  795.   call make_book 'oct-faq.inf', 'FAQ about Octave', ''
  796.   call make_book 'octave.inf', 'GNU Octave', ''
  797.   call make_book 'liboct.inf', 'Octave C++ Classes', ''
  798.  
  799.   return;
  800.  
  801. make_book: procedure expose octave_folder_id octave_home
  802. parse arg name, title, parm
  803.  
  804.   file = to_os2_sep(octave_home) || "\doc\" || name;
  805.  
  806.   rc = SysCreateObject('WPProgram', title, octave_folder_id, ,
  807.                       'PROGTYPE=PM;EXENAME=VIEW.EXE;PARAMETERS='||file||parm, ,
  808.                       'replace');
  809.  
  810.   if rc == 1 then say "info: Book object" title "created successfully."
  811.   else            say "notice: Could not create book object" title "."
  812.   return;
  813.  
  814. /*
  815. *******************************************************************************
  816. ** Determine the drive OS/2 is booted from                                   **
  817. *******************************************************************************
  818. */
  819. get_boot_drive: procedure expose debug
  820.   irc = SysIni("BOTH", "FolderWorkareaRunningObjects",,
  821.                "ALL:", "Objects");
  822.   boot1 = left(Objects.1, 2);;
  823.   do i = 2 to Objects.0
  824.     if (to_upper(right(Objects.i, 7)) == "DESKTOP")           then boot1 = left(Objects.i, 2);
  825.     if (to_upper(right(Objects.i,17)) == "ARBEITSOBERFLÄCHE") then boot1 = left(Objects.i, 2);
  826.   end
  827.   boot2 = substr(translate(value("PATH", , "OS2ENVIRONMENT")), pos("\OS2\SYSTEM", translate(value("PATH", , "OS2ENVIRONMENT")))-2, 2);
  828.   rc = SysFileTree(boot1 || "\config.sys", cfg, "FO");
  829.   if ((to_upper(boot1) <> to_upper(boot2)) | (cfg.0 <> 1)) then
  830.     do
  831.       say "error: Unable to determine the boot drive!";
  832.       exit;
  833.     end
  834.   return boot1;
  835.  
  836. /*
  837. *******************************************************************************
  838. ** Replace old pathes                                                        **
  839. *******************************************************************************
  840. */
  841. subst_paths: procedure expose debug
  842. parse arg path_arg, old_path, new_path
  843.   path= to_os2_sep(path_arg);
  844.   old = to_os2_sep(old_path);
  845.   new = to_os2_sep(new_path);
  846.  
  847.   p = 0;
  848.   do while(1)
  849.     p = pos(to_upper(old), to_upper(path), p + 1);
  850.     if (p == 0) then
  851.       do
  852.         if (substr(path, length(path)) == ";") then return path || new || ";";
  853.         else                                        return path || ";" || new;
  854.       end
  855.     if (p <> 1) then
  856.       do
  857.         if (substr(path, p - 1, 1) <> ";") then iterate;
  858.       end
  859.     q = pos(";", path, p);
  860.     if (q == 0) then old_path = substr(path, p);
  861.     else             old_path = substr(path, p, q - p);
  862.     if (to_upper(old_path) <> to_upper(old)) then iterate;
  863.     if (q == 0) then return substr(path, 1, p-1) || new;
  864.     else             return substr(path, 1, p-1) || new || substr(path, q);
  865.   end
  866.  
  867. /*
  868. *******************************************************************************
  869. ** Utilities                                                                 **
  870. *******************************************************************************
  871. */
  872. to_upper: procedure
  873. parse arg string
  874.   return translate(string, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz");
  875.  
  876. to_lower: procedure
  877. parse arg string
  878.   return translate(string, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  879.  
  880. to_unix_sep: procedure
  881. parse arg string
  882.   return translate(string, "/", "\");
  883.  
  884. to_os2_sep: procedure
  885. parse arg string
  886.   return translate(string, "\", "/");
  887.